<meta charset="utf-8">
(#) Missing `layout_width` or `layout_height` attributes

!!! ERROR: Missing `layout_width` or `layout_height` attributes
   This is an error.

Id
:   `RequiredSize`
Summary
:   Missing `layout_width` or `layout_height` attributes
Note
:   **This issue is disabled by default**; use `--enable RequiredSize`
Severity
:   Error
Category
:   Correctness
Platform
:   Android
Vendor
:   Android Open Source Project
Feedback
:   https://issuetracker.google.com/issues/new?component=192708
Since
:   Initial
Affects
:   Kotlin and Java files and resource files
Editing
:   This check can *not* run live in the IDE editor
Implementation
:   [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/RequiredAttributeDetector.java)
Tests
:   [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/RequiredAttributeDetectorTest.java)
Copyright Year
:   2012

All views must specify an explicit `layout_width` and `layout_height`
attribute. There is a runtime check for this, so if you fail to specify
a size, an exception is thrown at runtime.

It's possible to specify these widths via styles as well. GridLayout, as
a special case, does not require you to specify a size.

(##) Example

Here is an example of lint warnings produced by this check:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text
res/layout/size.xml:13:Error: The required layout_height attribute is
missing [RequiredSize]
    &lt;RadioButton
     -----------
res/layout/size.xml:18:Error: The required layout_width attribute is
missing [RequiredSize]
    &lt;EditText
     --------
res/layout/size.xml:23:Error: The required layout_width and
layout_height attributes are missing [RequiredSize]
    &lt;EditText
     --------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here is the source file referenced above:

`res/layout/size.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" &gt;

    &lt;RadioButton
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" /&gt;

    &lt;RadioButton
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:text="Button" /&gt;

    &lt;EditText
        android:id="@+id/edittext"
        android:layout_height="wrap_content"
        android:text="EditText" /&gt;

    &lt;EditText
        android:id="@+id/edittext2"
        android:text="EditText"&gt;
        &lt;tag id="@+id/test" /&gt;
    &lt;/EditText&gt;
&lt;/LinearLayout&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can also visit the
[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/RequiredAttributeDetectorTest.java)
for the unit tests for this check to see additional scenarios.

The above example was automatically extracted from the first unit test
found for this lint check, `RequiredAttributeDetector.test`.
To report a problem with this extracted sample, visit
https://issuetracker.google.com/issues/new?component=192708.

(##) Suppressing

You can suppress false positives using one of the following mechanisms:

* Using a suppression annotation like this on the enclosing
  element:

  ```kt
  // Kotlin
  @Suppress("RequiredSize")
  fun method() {
     inflate(...)
  }
  ```

  or

  ```java
  // Java
  @SuppressWarnings("RequiredSize")
  void method() {
     inflate(...);
  }
  ```

* Using a suppression comment like this on the line above:

  ```kt
  //noinspection RequiredSize
  problematicStatement()
  ```

* Using a special `lint.xml` file in the source tree which turns off
  the check in that folder and any sub folder. A simple file might look
  like this:
  ```xml
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;lint&gt;
      &lt;issue id="RequiredSize" severity="ignore" /&gt;
  &lt;/lint&gt;
  ```
  Instead of `ignore` you can also change the severity here, for
  example from `error` to `warning`. You can find additional
  documentation on how to filter issues by path, regular expression and
  so on
  [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html).

* In Gradle projects, using the DSL syntax to configure lint. For
  example, you can use something like
  ```gradle
  lintOptions {
      disable 'RequiredSize'
  }
  ```
  In Android projects this should be nested inside an `android { }`
  block.

* For manual invocations of `lint`, using the `--ignore` flag:
  ```
  $ lint --ignore RequiredSize ...`
  ```

* Last, but not least, using baselines, as discussed
  [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html).

<!-- Markdeep: --><style class="fallback">body{visibility:hidden;white-space:pre;font-family:monospace}</style><script src="markdeep.min.js" charset="utf-8"></script><script src="https://morgan3d.github.io/markdeep/latest/markdeep.min.js" charset="utf-8"></script><script>window.alreadyProcessedMarkdeep||(document.body.style.visibility="visible")</script>